﻿$(document).ready(function () {
    //验证按钮
    $('#siteverify').click(function () {
        var urltest = RegExp('[a-zA-Z0-9\-\.]+\.(com|org|net|COM|ORG|NET)');
        if (document.getElementById('LinkAddr').value != '' && urltest.test(document.getElementById('LinkAddr').value)) {
            $('#SiteVerifyWidgetVerifyMethodBlock').css('display', 'block');
            $('#siteverifybtnblock').css('display', 'none');
            $('#SiteVerifyWidgetDomainDisplay').text(document.getElementById('LinkAddr').value);
        }
        else {
            if (document.getElementById('blankurl') === null)
                $('#siteverify').after('<span id="blankurl">网址格式不正确</span>');
        }
    })
    //取消按钮
    $('#SiteVerifyWidgetVerifyCancelBtn').click(function () {
        $('#SiteVerifyWidgetVerifyMethodBlock').css('display', 'none');
        $('#siteverifybtnblock').css('display', 'block');
    })
    //下载验证文件按钮
    document.getElementById('SiteVerifyWidgetVerifyFileDownloadUrl').onclick = function () {
        var tmpelem = document.createElement("iframe");
        tmpelem.src = urltodownloadverify;
        tmpelem.style.display = "none";
        document.body.appendChild(tmpelem);
    }
    //完成验证按钮  todo 添加等待动画
    document.getElementById('SiteVerifyWidgetVerifyTestBtn').onclick = function () {
        $('#AjaxLoading').css('display', 'block');
        var data = { linkaddr: $('#SiteVerifyWidgetDomainDisplay').text() };
        var jqxhr = $.post(urltoverify, data).success(OnSucess);
    }
})

function OnSucess(data) {
    $('#AjaxLoading').css('display', 'none');
    if (data == '0') {
        document.getElementById('ui-validityshower-failure info error').setAttribute('style', 'display:block');
        document.getElementById('ui-validityshower-success info success').setAttribute('style', 'display:none');
    }
    else {
        document.getElementById('ui-validityshower-success info success').setAttribute('style', 'display:block');
        document.getElementById('ui-validityshower-failure info error').setAttribute('style', 'display:none');
        document.getElementById('isvalidate').setAttribute('value', '1');  //enable the register
    }
}